package com.wsoft.bpm.node;

import com.wsoft.bpm.enums.ListenerEvent;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * 监听器
 *
 * @Author zhonglj
 * @Date 2024-09-11 9:42
 */
@Getter
@Setter
@Accessors(chain = true)
public class ActivityListener extends ActivityXml {

    private String event;
    private String clz;
    private String expression;
    private String delegateExpression;
    private List<ListenerField> fields;

    public ActivityListener() {
        putXmlKey("clz", "class");
    }

    public void setEvent(String event) {
        this.event = event;
        if (event.equals(ListenerEvent.EXECUTION_START.getValue())
                || event.equals(ListenerEvent.EXECUTION_END.getValue())) {
            setTagName("activiti:executionListener");

        } else if (event.equals(ListenerEvent.TASK_CREATE.getValue())
                || event.equals(ListenerEvent.TASK_ASSIGNMENT.getValue())
                || event.equals(ListenerEvent.TASK_COMPLETE.getValue())
                || event.equals(ListenerEvent.TASK_ALL.getValue())) {
            setTagName("activiti:taskListener");
        }
    }
}
